package com.wedo.mall.activity.user;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;

import com.e.library.activity.EActivity;
import com.e.library.entity.User;
import com.wedo.mall.R;
import com.wedo.mall.activity.login.WLogin;

import butterknife.BindView;
import butterknife.OnClick;

public class MyIntegralActivity extends EActivity {

    @BindView(R.id.iv_myintegral_bg) ImageView iv_myintegral_bg;
    @BindView(R.id.tv_point) TextView tv_point;


    @Override
    protected int layout() {
        return R.layout.activity_my_integral;
    }

    @Override
    protected void onActivityCreated(Bundle state) {
        fixMyWalletBGHeight();
        User user = WLogin.user();
        tv_point.setText(user.point);
    }

    /**
     * 动态适配头部背景图片高度
     */
    private void fixMyWalletBGHeight(){
        BitmapFactory.Options options = new BitmapFactory.Options();
        Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.myintegral_bg, options);
        //获取bitmap的宽度
        float bitWidth = bitmap.getWidth();
        //获取bitmap的宽度
        float bitheight = bitmap.getHeight();
        //计算出图片的高宽比，然后按照图片的比列去缩放图片
        float bitScale =  bitheight / bitWidth;
        //获取屏幕宽度
        WindowManager wm = this.getWindowManager();
        int screenWidth = wm.getDefaultDisplay().getWidth();

        ViewGroup.LayoutParams  lp = iv_myintegral_bg.getLayoutParams();
        //设置imageView宽
        lp.height =  (int)(screenWidth * bitScale);
        iv_myintegral_bg.setLayoutParams(lp);

    }

    @OnClick(R.id.iv_leftarrow)
    protected void onLeftArrowClick(){
        defaultFinish();
    }

    @OnClick(R.id.rl_detail)
    protected void onIntegralDetailClick(){
        toActivity(IntegralDetailActivity.class);
    }

    @OnClick(R.id.rl_shop)
    protected void onIntegralShopClick(){
        toActivity(IntegralShopActivity.class);
    }

}
